// Generated from <%= script_name %>

package <%= package_name %>;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.shopify.graphql.support.AbstractResponse;
import com.shopify.graphql.support.Arguments;
import com.shopify.graphql.support.Error;
import com.shopify.graphql.support.Query;
import com.shopify.graphql.support.SchemaViolationError;
import com.shopify.graphql.support.TopLevelResponse;
import com.shopify.graphql.support.Input;
<% imports.each do |import| %>
  import <%= import %>;
<% end %>

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class <%= type.name %> implements Serializable {
    <% type.required_input_fields.each do |field| %>
      private <%= java_input_type(field.type) %> <%= escape_reserved_word(field.camelize_name) %>;
    <% end %>
    <% type.optional_input_fields.each do |field| %>
      private Input<<%= java_input_type(field.type) %>> <%= escape_reserved_word(field.camelize_name) %> = Input.undefined();
    <% end %>

    <% unless type.required_input_fields.empty? %>
      public <%= type.name %>(<%= type.required_input_fields.map{ |field| "#{java_input_type(field.type)} #{escape_reserved_word(field.camelize_name)}" }.join(', ') %>) {
          <% type.required_input_fields.each do |field| %>
              this.<%= escape_reserved_word(field.camelize_name) %> = <%= escape_reserved_word(field.camelize_name) %>;
          <% end %>
      }
    <% end %>

    <% type.required_input_fields.each do |field| %>
      <%= java_annotations(field) %>
      public <%= java_input_type(field.type) %> get<%= field.classify_name %>() {
          return <%= escape_reserved_word(field.camelize_name) %>;
      }

      public <%= type.name %> set<%= field.classify_name %>(<%= java_annotations(field, in_argument: true) %><%= java_input_type(field.type) %> <%= escape_reserved_word(field.camelize_name) %>) {
          this.<%= escape_reserved_word(field.camelize_name) %> = <%= escape_reserved_word(field.camelize_name) %>;
          return this;
      }

    <% end %>
    <% type.optional_input_fields.each do |field| %>
      <%= java_annotations(field) %>
      public <%= java_input_type(field.type) %> get<%= field.classify_name %>() {
          return <%= escape_reserved_word(field.camelize_name) %>.getValue();
      }

      public Input<<%= java_input_type(field.type) %>> get<%= field.classify_name %>Input() {
          return <%= escape_reserved_word(field.camelize_name) %>;
      }

      public <%= type.name %> set<%= field.classify_name %>(<%= java_annotations(field, in_argument: true) %><%= java_input_type(field.type) %> <%= escape_reserved_word(field.camelize_name) %>) {
          this.<%= escape_reserved_word(field.camelize_name) %> = Input.optional(<%= escape_reserved_word(field.camelize_name) %>);
          return this;
      }

      public <%= type.name %> set<%= field.classify_name %>Input(Input<<%= java_input_type(field.type) %>> <%= escape_reserved_word(field.camelize_name) %>) {
          if (<%= escape_reserved_word(field.camelize_name) %> == null) {
              throw new IllegalArgumentException("Input can not be null");
          }
          this.<%= escape_reserved_word(field.camelize_name) %> = <%= escape_reserved_word(field.camelize_name) %>;
          return this;
      }

    <% end %>

    public void appendTo(StringBuilder _queryBuilder) {
      String separator = "";
      _queryBuilder.append('{');
      <% type.required_input_fields.each do |field| %>
        _queryBuilder.append(separator);
        separator = ",";
        _queryBuilder.append("<%= field.name %>:");
        <%= generate_build_input_code(escape_reserved_word(field.camelize_name), field.type) %>
      <% end %>
      <% type.optional_input_fields.each do |field| %>
        if (this.<%= escape_reserved_word(field.camelize_name) %>.isDefined()) {
          _queryBuilder.append(separator);
          separator = ",";
          _queryBuilder.append("<%= field.name %>:");
          if (<%= escape_reserved_word(field.camelize_name) %>.getValue() != null) {
            <%= generate_build_input_code(escape_reserved_word(field.camelize_name).concat(".getValue()"), field.type) %>
          } else {
            _queryBuilder.append("null");
          }
        }
      <% end %>
      _queryBuilder.append('}');
    }
}
